package Classroom2;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        //创建对象
        Socket s = new Socket("127.0.0.1",12222);
        //加载本地文件
        BufferedInputStream bis = new BufferedInputStream(
                new FileInputStream("E:\\a.png"));
        //读本地文件，把这个文件发送给服务端
        BufferedOutputStream bos = new BufferedOutputStream(s.getOutputStream());
        byte [] bytes = new byte[1024*8];
        int len;
        while ((len = bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
            bos.flush();
        }
        //结束标记，结束上面这个io流
        s.shutdownOutput();
        bis.close();
        //接受服务器传的回写数据
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        String s1 = br.readLine();
        System.out.println(s1);
        //释放资源
        br.close();
        s.close();
    }
}
